<template>
  <transition>
  <div class="app-password-modify">
    <div class="module-form app-main">
      <mt-field label="原密码" placeholder="请输入原密码" v-model="pwdorigin"></mt-field>
      <mt-field label="新密码" placeholder="请输入新密码（至少6位数）" v-model="pwdnew"></mt-field>
      <mt-field label="确认密码" placeholder="请再次输入密码" v-model="pwdconfirm"></mt-field>

      <div class="button-content">
        <mt-button type="primary" @click="handleLogin">确认修改</mt-button>
      </div>
    </div>
  </div>
    </transition>
</template>

<script>
  import { Header,Cell,Field,Button,Toast } from 'mint-ui';
export default {
  components:{
    Header,
    Cell,
  },
  data () {
    return {
      pwdorigin:'',
      pwdnew:'',
      pwdconfirm:''
    }
  },
  mounted(){},
  methods:{
    handleLogin(){

      if(this.pwdorigin==''){
        Toast({
          message: '请输入原密码',
          position: 'middle',
          duration:1000
        });
        return false;
      }

      if(this.pwdnew==''){
        Toast({
          message: '请输入新密码',
          position: 'middle',
          duration:1000
        });
        return false;
      }
      if(this.pwdnew.length<6){
        Toast({
          message: '密码至少为6位数',
          position: 'middle',
          duration:1000
        });
        return false;
      }
      if(this.pwdconfirm==''){
        Toast({
          message: '请再次输入密码',
          position: 'middle',
          duration:1000
        });
        return false;
      }
      if(this.pwdnew!==this.pwdconfirm){
        Toast({
          message: '两次输入的密码不正确',
          position: 'middle',
          duration:1000
        });
        return false;
      }

      var params = new URLSearchParams();
      params.append('form.password', this.pwdorigin);
      params.append('form.newpassword', this.pwdnew);
      params.append('form.repassword', this.pwdconfirm);
      this.$axios({
        method: 'post',
        url:'gp/user!changePsd.do',
        data:params
      }).then((res)=>{
        if(res.data.statusCode==200){
        Toast({
          message: res.data.message,
          position: 'middle',
          duration:1500
        });
        this.$axios({
          method: 'post',
          url:'gp/login!logout.do'
        }).then((res)=>{
          localStorage.removeItem('phone');
        localStorage.removeItem('password');
        setTimeout(()=>{
          this.$router.push({path:'/index'})
      },1500)
      });
      }else{
        Toast({
          message: res.data.message,
          position: 'middle',
          duration:1000
        });
        return false;
      }
    });
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->

<style>
  .app-password-modify .button-content{
    padding:24px;
  }
  .app-password-modify .button-content .mint-button{
    display: block;
    width: 100%;
  }
  .app-password-modify .mint-field .mint-cell-title{
    width:90px;
  }
</style>
